package com.qf.cx.simplenms.core.util;

import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.function.Consumer;

import com.qf.cx.simplenms.link.api.LinkManager.ReaderSource;
import com.qf.cx.simplenms.persist.entity.AntennaEntity;
import com.qf.cx.simplenms.persist.entity.ReaderEntity;
import com.qf.cx.simplenms.reader.model.AntennaModel;
import com.qf.cx.simplenms.reader.model.ReaderModel;

public final class ModelUtils {
	public static ReaderModel createReaderModel(final ReaderEntity t) {
		ReaderModel readerModel = new ReaderModel();
		ReaderSource readerSource = new ReaderSource();
		readerModel.setReaderSource(readerSource);
		readerModel.setName(t.getName());
		readerSource.setIp(t.getIp());
		readerSource.setPort(t.getPort());
		readerSource.setDeviceSn(t.getDeviceSn());
		readerSource.setLinkType(t.getLinkType());
		List<AntennaEntity> antennaEntities = t.getAntennaEntities();
		Set<AntennaModel> antennas = new HashSet<>(antennaEntities.size());
		antennaEntities.forEach(new Consumer<AntennaEntity>() {
			@Override
			public void accept(final AntennaEntity t) {
				AntennaModel ant = createAntennaModel(readerModel, t);
				antennas.add(ant);
			}

		});
		readerModel.addAntennas(antennas);
		return readerModel;
	}

	public static AntennaModel createAntennaModel(final ReaderModel readerModel, final AntennaEntity t) {
		AntennaModel ant = new AntennaModel();
		ant.setAntennaNo(t.getAntenna());
		ant.setProtocol(t.getProtocol());
		ant.setReaderModel(readerModel);
		return ant;
	}
	
	private ModelUtils(){
	}
}
